from app.core.img_opencv import *

# region 万兽挑战
def wanshou_work(scale):
    """
    万兽挑战过程
    """
    wait_image('app_img/wszf_challenge/1_1.png', threshold=0.7, scale=scale)
    if_exist_click_image('app_img/public_img/yes.png', threshold=0.7, scale=scale)
    success_num = 0
    all_num = 0
    # 循环挑战逻辑
    while True:    
        click_image('app_img/wszf_challenge/2.png', threshold=0.7, scale=scale)

        # 挑战弹窗判断
        if(is_image_now('app_img/wszf_challenge/4_1.png', threshold=0.7, scale=scale)):
            success_num=15
            break
        if(is_image_now('app_img/wszf_challenge/4.png', threshold=0.7, scale=scale)):
            click_image('app_img/public_img/no.png', threshold=0.7, scale=scale)
            success_num=15
            break
        
        # 正常挑战逻辑
        wait_image('app_img/wszf_challenge/3.png', threshold=0.7, scale=scale)
        if(is_image_now('app_img/wszf_challenge/3_1.png', threshold=0.7, scale=scale)):
            success_num += 1
            all_num=0
        click_image('app_img/wszf_challenge/3.png', threshold=0.7, scale=scale)
        all_num += 1

        # 挑战结束判断
        wait_image('app_img/wszf_challenge/1_1.png', threshold=0.7, scale=scale)
        if(success_num==15 or all_num==5):
            break    
    return success_num